package com.example.linuxweb.model;

import java.util.ArrayList;
import java.util.List;

public class FileNode {
    private String name;
    private boolean isDirectory;
    private String content;
    private List<FileNode> children;
    private FileNode parent;

    public FileNode(String name, boolean isDirectory) {
        this.name = name;
        this.isDirectory = isDirectory;
        this.children = new ArrayList<>();
        this.content = "";
    }

    // Getters and Setters
    public String getName() {
        return name;
    }

    public boolean isDirectory() {
        return isDirectory;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public List<FileNode> getChildren() {
        return children;
    }

    public FileNode getParent() {
        return parent;
    }

    public void setParent(FileNode parent) {
        this.parent = parent;
    }

    public void addChild(FileNode child) {
        child.setParent(this);
        this.children.add(child);
    }

    public FileNode findChild(String name) {
        for (FileNode child : children) {
            if (child.getName().equals(name)) {
                return child;
            }
        }
        return null;
    }

    public String getPath() {
        if (parent == null) {
            return "/";
        }
        return parent.getPath() + name + (isDirectory ? "/" : "");
    }
}